package at.jsug.topicvoting.gwt1.client.view;

import at.jsug.topicvoting.gwt1.client.logic.event.SaveTopicEvent;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class NewTopicDialog extends DialogBox {

	private final TextBox inpTitle = new TextBox();
	
	public NewTopicDialog() {
		super(false, true); // autoHide, modal
		
		this.setText("Add new Topic");
		
		
		final Button btnSave = new Button("Save");
		final Button btnClose = new Button("Close");

		btnSave.addClickListener(new ClickListener() { public void onClick(Widget sender) { onSave(); } });
		btnClose.addClickListener(new ClickListener() { public void onClick(Widget sender) { onClose(); } });
		
		final HorizontalPanel controlBar = new HorizontalPanel();
		controlBar.add(btnSave);
		controlBar.add(btnClose);

		final VerticalPanel rootPanel = new VerticalPanel();
		rootPanel.add(this.inpTitle);
		rootPanel.add(controlBar);
		this.setWidget(rootPanel);
	}
	
	private void onSave() {
		System.out.println("NewTopicDialog.onSave()");
		
		new SaveTopicEvent(
			this.inpTitle.getText()
		).dispatch();
		
		this.hide();
	}
	
	private void onClose() {
		this.hide();
	}
	
}
